<include file="public@header"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="#">设置首页轮播图</a></li>
    </ul>
    <form action="{:url('TechAdmin/addImages')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
        <div class="row">
            <div class="col-md-9">
                <table class="table table-bordered">
                    <tr>
                        <th style="text-align: center" width="300px">首页轮播图（最多上传四张）(必填)</th>
                        <td>
                            <ul id="photos" class="pic-list list-unstyled form-inline">
                                <notempty name="images">
                                    <foreach name="images" item="vo" key="k">
                                        <li id="saved-image{$k}">
                                            <input id="photo-{$k}" type="hidden" name="imgs[]" value="{$vo}">
                                            <img id="photo-{$k}-preview" src="<?php echo  'http://'.$_SERVER['HTTP_HOST'].'/public/upload/'.$vo  ?>" style="height:80px;width: 80px;"
                                                 onclick="imagePreviewDialog(this.src);">
                                            <a href="javascript:uploadOneImage('图片上传','#photo-{$k}');">替换</a>
                                            <a href="javascript:(function(){$('#saved-image{$k}').remove();})();">移除</a>
                                        </li>
                                    </foreach>
                                </notempty>
                            </ul>
                            <a href="javascript:uploadImages();"
                               class="btn btn-default btn-sm">选择图片</a>
                        </td>
                    </tr>
                </table>
                <div class="form-group">
                    <div class="col-sm-offset-6 col-sm-6">
                        <button type="submit" class="btn btn-primary js-ajax-submit">提交</button>
                    </div>
                </div>
            </div>

        </div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="imgs[]" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
<script>
    //=================上传图片===========================
    function uploadImages(){
        var len = $('#photos li').length;
        if(len>=4){
            alert('最多只能上传4张图片！');
        }else{
            uploadMultiImage('图片上传','#photos','photos-item-tpl');
        }
    }

    $(function(){
        $('.btn-cancel-thumbnail').click(function () {
            $('#js-thumbnail-input-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#js-thumbnail-input').val('');
        });

        $('.btn-cancel-thumbnail2').click(function () {
            $('#js-thumbnail-input-preview2').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#js-thumbnail-input2').html('');
        });
    });

</script>

</body>
</html>